package com.itqf.demo03;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @Description:  如何排除一下特殊时间，特殊时间不执行任务
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/15
 * @Time: 下午2:41
 */
public class Demo03 {

    public  static  void  main(String[]args) throws  Exception{
        //1,调度器
        Scheduler scheduler  = new StdSchedulerFactory().getScheduler();
        //2,构建不执行的日历集合对象
        AnnualCalendar annualCalendar = new AnnualCalendar();

        Calendar calendar = new GregorianCalendar(2020,
                9,1);
       annualCalendar.setDayExcluded(calendar,true);

        Calendar today = new GregorianCalendar(2020,
                9,15);
        annualCalendar.setDayExcluded(today,true);

        //3.设置不执行的时间
        scheduler.addCalendar("holidays",annualCalendar,false,false);

        //4.构建Trigger
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
                .modifiedByCalendar("holidays").build();
        //modifiedByCalendar("holidays")   跟新cron触发器

        //5.Jobdetail
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJob").build();

        //6.注册trigger和jobdetail
        scheduler.scheduleJob(jobDetail,cronTrigger);

        //7.启动任务
        scheduler.start();



    }


}
